package cn.xuguowen.bean;

import lombok.Data;

import java.io.Serializable;

/**
 * ClassName: Result
 * Package: cn.xuguowen
 * Description:
 *
 * @Author 徐国文
 * @Create 2023/2/26 14:34
 * @Version 1.0
 */
@Data
public class Result<T> implements Serializable {

    public static final Long serialVersionUID = 1L;

    private Result(){}

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static Result ok() {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setSuccess(true);
        result.setMessage(ResultMessage.SUCCESS);
        return result;
    }

    public static Result ok(Integer resultCode,String resultMessage) {
        Result result = new Result();
        result.setCode(resultCode);
        result.setSuccess(true);
        result.setMessage(resultMessage);
        return result;
    }

    // 注意：这里用到了泛型方法
    public static <T> Result ok(Integer resultCode,String resultMessage,T data) {
        Result result = new Result();
        result.setCode(resultCode);
        result.setSuccess(true);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

    // 注意：这里用到了泛型方法
    public static <T> Result ok(T data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setSuccess(true);
        result.setMessage(ResultMessage.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        result.setCode(ResultCode.ERROR);
        result.setSuccess(true);
        result.setMessage(ResultMessage.ERROR);
        return result;
    }

    public static Result fail(Integer resultCode,String resultMessage) {
        Result result = new Result();
        result.setCode(resultCode);
        result.setSuccess(true);
        result.setMessage(resultMessage);
        return result;
    }

    // 注意：这里用到了泛型方法
    public static <T> Result fail(Integer resultCode,String resultMessage,T data) {
        Result result = new Result();
        result.setCode(resultCode);
        result.setSuccess(true);
        result.setMessage(resultMessage);
        result.setData(data);
        return result;
    }

    // 注意：这里用到了泛型方法
    public static <T> Result fail(T data) {
        Result result = new Result();
        result.setCode(ResultCode.ERROR);
        result.setSuccess(true);
        result.setMessage(ResultMessage.ERROR);
        result.setData(data);
        return result;
    }


}
